﻿@model IEnumerable<Commission.Models.TransactionHistory>
@using MyResources = Commission.Resources.AppResource
@using Microsoft.AspNet.Identity
@using Commission.Models;

@{
    ViewBag.Title = @MyResources.LabelAccount;
}

<h2>@MyResources.LinkAccountList</h2>

@section MyJavascript {
    <script type="text/javascript">
    $(function () {
        $('#UserName').autocomplete(
        {
            source: '@Url.Action("CustomerSearch", "Customer")'
        }
        );
    });
    </script>
}

@section Sortable {
    @Scripts.Render("~/bundles/sortable")
}

@using (Html.BeginForm("Index", "Transaction", FormMethod.Get))
{
    <p>
        @MyResources.LabelDateFrom:
        @Html.JQueryUI().Datepicker("dateFrom", ViewBag.DateFrom,
             new { @class = "form-control-date searchtext", @style = "width:88px" })

        @MyResources.LabelDateTo:
        @Html.JQueryUI().Datepicker("dateTo", ViewBag.DateTo,
             new { @class = "form-control-date searchtext", @style = "width:88px" })

        @if (User.IsInRole("Admin"))
        {
            @MyResources.LabelCustomer
            @Html.Raw(" : ")
            @Html.TextBox("UserName", ViewBag.CurrentFilter as string,
                new { @class = "form-control searchtext" })
        }

        @MyResources.LabelAccountType :
        @Html.DropDownList(
             "TransactionTypeID",
             (IEnumerable<SelectListItem>)ViewBag.TransactionTypes, string.Empty,
             new { @class = "form-control searchtext", @style = "width:138px" }
            )
        <input type="submit" value="@MyResources.LabelSearch" style="height:28px" />
    </p>
}

<table class="table hoverTable sortable">
    <tr>
        <th class="text-center" style="width:130px">
            @MyResources.LabelTransactionDate
        </th>

        @if (User.IsInRole("Admin"))
        {
            <th class="text-left" style="width:220px;">
                @MyResources.LabelCustomer
            </th>
        }

        <th class="text-left" style="width:110px;">
            @MyResources.LabelAccountType
        </th>

        <th class="text-left" style="width:220px;">
            @MyResources.LabelForCustomer
        </th>

        <th class="text-center" style="width:60px">
            @MyResources.LabelPoint
        </th>

        <th class="text-center" style="width:90px;">
            @MyResources.LabelTotal
        </th>

        <th class="text-center" style="width:90px;">
            @MyResources.LabelRemain
        </th>

        <th class="text-center">
            @MyResources.LabelDescription
        </th>

        <th class="text-left" style="width:60px;"></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td class="text-center">
                @Html.Label(item.AccountDate.ToShortDateString(), new { @class = "LabelNormal" })
            </td>

            @if (User.IsInRole("Admin"))
            {
                <td class="text-left">
                    @Html.ActionLink(
                         item.Customer.DisplayName,
                         "Details", "Customer",
                         new { id = item.CustomerID }, new { @class = "LabelNormal" })
                </td>
            }

            <td class="text-left">
                @Html.DisplayFor(modelItem => item.AccountType)
            </td>

            <td class="text-left">
                @if (item.SponsoredCustomer != null) {
                @Html.ActionLink(
                         item.SponsoredCustomer.DisplayName,
                         "Details", "Customer",
                         new { id = item.SponsoredCustomerID }, new { @class = "LabelNormal" })
                }
            </td>

            <td class="text-right">
                @Html.Raw(string.Format("{0:#,0.0}", item.Point))
            </td>
            
            <td class="text-right" title="@Html.Raw(item.AmountDetail)">
                @Html.Raw(string.Format("{0:#,0}", item.TotalAmount))
            </td>

            <td class="text-right" title="@Html.Raw(item.CumulativeAmountDetail)">
                @Html.Raw(string.Format("{0:#,0}", item.CumulativeAmount))
            </td>

            <td>
                @if (!User.IsInRole("Admin") && item.AccountType != AccountType.Input) { 
                    @Html.DisplayFor(modelItem => item.Description)
                }
            </td>
            <td>
                @Html.ActionLink(@MyResources.LinkDetail, "Details", new { id = item.ID })
            </td>
        </tr>
    }
    
    <tfoot>
        <tr>
            @if (User.IsInRole("Admin"))
            {
                <th>
                </th>
            }
            <th>
            </th>
            
            <th>
                
            </th>

            <th>
            </th>
            <th>
                Tổng
            </th>
            
            <th class="text-right">
                @Html.Raw(string.Format("{0:#,0}", @Model.Sum(i => i.TotalAmount)))
            </th>
            
            <th></th>

            <th>
            </th>

            <th>
            </th>
        </tr>
    </tfoot>
</table>

